package com.example.a17376052_wcp_finaltest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.a17376052_wcp_finaltest.fragment.TomActivity;

import org.litepal.LitePal;

import java.util.List;

import entire.Account;

public class MainActivity extends AppCompatActivity {
    private Button mBtnButton, mBtnButton2;
    private EditText et_account, et_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et_account = findViewById(R.id.et_account);
        et_password = findViewById(R.id.et_password);
        mBtnButton = findViewById(R.id.btn_button);
        mBtnButton2 = findViewById(R.id.btn_button2);
        mBtnButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ResigerActivity.class);
                startActivity(intent);
            }
        });
        mBtnButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String account = et_account.getText().toString().trim();
                String password = et_password.getText().toString().trim();
                List<Account> accountList = LitePal.where("account=?", account).find(Account.class);
                for (Account account1 : accountList) {
                    if (account1.getPassword().equals(password)) {
                        Intent intent = new Intent(MainActivity.this, TitleActivity.class);
                        startActivity(intent);
                        Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });

    }
}



